package com.dream.testtubebaby.adapter;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;

import com.dream.testtubebaby.R;
import com.dream.testtubebaby.activity.DoctorDescActivity;
import com.dream.testtubebaby.data.doctor.Doctor;
import com.dream.testtubebaby.utils.AppUtil;
import com.dream.testtubebaby.utils.ImageLoader;
import com.dream.testtubebaby.utils.ViewHolder;

public class MyDoctorListAdapter extends CommonAdapter<Doctor> {

	public MyDoctorListAdapter(Context context, List<Doctor> mDatas,
			int itemLayoutId) {
		super(context, mDatas, itemLayoutId);
	}

	public void setDatas(List<Doctor> mDatas) {
		this.mDatas.clear();
		this.mDatas.addAll(mDatas);
	}

	public void addAll(List<Doctor> mDatas) {
		this.mDatas.addAll(mDatas);
	}
	
	@Override
	public void convert(final ViewHolder helper, final Doctor item) {
		helper.setText(R.id.my_doctor_name_tv, item.getName());
		ImageView photo = helper.getView(R.id.mydoctor_img);
		photo.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(mContext,
						DoctorDescActivity.class);
				intent.putExtra(DoctorDescActivity.DOCTOR_ID, item.getId());
				mContext.startActivity(intent);
			}
		});
		if(item.getPhoto_url() != null){
			ImageLoader.getInstance().loadNetWorkImage(AppUtil.getCompletePhotoUrl(item.getPhoto_url()), photo);
		}
	}
}
